export function arrayMethods() {
  const newArray = Object.create(Array.prototype);
  const methods = [
    "push",
    "pop",
    "shift",
    "unshift",
    "splice",
    "reverse",
    "sort",
  ];
  methods.forEach((method) => {
    Object.defineProperty(newArray, method, {
      value: function (...args) {
        const result = Array.prototype[method].apply(this, args);
        let inserted;
        switch (method) {
          case "push":
          case "unshift":
            console.log(method, args);
            inserted = args;
            break;
          case "splice":
            inserted = args.slice(2);
            break;
          default:
        }
        if (inserted) {
          //进行监听
          this.__ob__.observeArray(inserted);
        }
        this.__ob__.dep.notify();
        return result;
      },
    });
  });
  return newArray;
}
